
$('#login').on('click',function () {
    if($('#username').val() == ''){
        console.log("请输入用户名");
    }else if($('#password').val() == ''){
        console.log("请输入密码");
    }else {
        console.log("登录");
        $.ajax({
            url: contextPath+"/loginUser?username="+$("#username").val()+"&password="+$("#password").val(),
            type: "POST",
            dateType:"json",
            success: function(data) {
                console.log(data);
                if(data.message== "登录成功!"){
                    if(data.role=="学习者"){
                        window.location.href='Student/index.html';
                    }else if(data.role=="管理员"){
                        window.location.href='Manager/index.html';
                    }else if(data.role=="系统管理员"){
                        window.location.href='administrator/index.html';
                    }else{
                    }
                }else{
                    bootbox.alert({
                        message:data.message,
                        size:'small'
                    });
                }
            },
            error:function () {
            }
        });
    }
    return false;
});
$('#register').on('click',function () {
    $('.userregister').show();
    $('.userlogin').hide();

    $('#rregister').on('click',function () {
        var ss = new Object();
        ss.rusername = $('input[name="rusername"]').val();
        ss.rname = $('input[name="rname"]').val();
        ss.rsex = $('input[name="rsex"]:checked').val();
        ss.rpassword = $('input[name="rpassword"]').val();
        ss.rchpassword = $('input[name="rchpassword"]').val();
        ss.ruserid = $('input[name="ruserid"]').val();

        $.ajax({
            type:"POST",
            url:contextPath+"/learner/new",
            async: false,
            contentType: "application/json; charset=utf-8",
            data:JSON.stringify(ss),
            dataType:"json",
            success:function (data) {
                console.log(data.message);
                if(data.message == "注册成功!"){
                    $('.userregister').hide();
                    $('.userlogin').show();
                }else{
                    bootbox.alert({
                        message:data,
                        size:'small'
                    });
                }
            },
            error:function () {
            }
        });
    });
    $('#retur').on('click',function () {
        $('.userlogin').show();
        $('.userregister').hide();
    })
});